Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.generateQuestionUrl = function(e) {
    return c.apply(this, arguments);
};

var e = require("../@babel/runtime/helpers/regeneratorRuntime"), t = require("../@babel/runtime/helpers/asyncToGenerator"), r = require("request"), n = require("crypto-js"), s = require("../utils/api"), a = "https://bmyi-q.rich-healthcare.com/";

function c() {
    return (c = t(e().mark(function t(n) {
        var c, p, b, g, f, h, d, m;
        return e().wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return console.log("体检号", n), c = i(n), p = l(n), console.log("已体检天数", p), e.next = 6, 
                r.request(r.HttpMethod.GET, s.apiRoute.selectWcaSimpleInstitutionByCode + c, {});

              case 6:
                if (!(b = e.sent).success || "10" != b.data.brandName) {
                    e.next = 31;
                    break;
                }
                return console.log("体检品牌", "瑞慈"), e.next = 11, o(n, "3");

              case 11:
                return g = e.sent, e.next = 14, o(n, "5");

              case 14:
                return f = e.sent, e.next = 17, o(n, "10");

              case 17:
                if (h = e.sent, console.log(g, f, h), !(g || p > 30)) {
                    e.next = 24;
                    break;
                }
                if (f) {
                    e.next = 24;
                    break;
                }
                return d = u("5", n), m = "?system_code=wechat_applet&project_type=5&check_no=" + n + "&signature=" + d, 
                e.abrupt("return", a + "s/b0c13886bca04f57be69f3a29b791a5f" + m);

              case 24:
                if (g || !(p <= 30)) {
                    e.next = 29;
                    break;
                }
                if (h) {
                    e.next = 29;
                    break;
                }
                return d = u("10", n), m = "?system_code=wechat_applet&project_type=10&check_no=" + n + "&signature=" + d, 
                e.abrupt("return", a + "s/5a85cb5a634f43289fd38b49beb7271c" + m);

              case 29:
                e.next = 32;
                break;

              case 31:
                console.log("体检品牌", "幸元会");

              case 32:
                return e.abrupt("return", "");

              case 33:
              case "end":
                return e.stop();
            }
        }, t);
    }))).apply(this, arguments);
}

function o(e, t) {
    return new Promise(function(r, n) {
        wx.request({
            url: a + "tduck-api/user/project/result/isFillIn?projectType=".concat(t, "&cardNo=&checkNo=").concat(e),
            method: "GET",
            dataType: "json",
            responseType: "text",
            success: function(e) {
                r(e.data.data.isFillIn);
            },
            fail: function(e) {
                n(!1);
            }
        });
    });
}

function u(e, t) {
    var r = "check_no" + t + "project_type" + e + "system_codewechat_appletC2E36869A18491E89F11D89713E419BA";
    return n.MD5(r).toString();
}

function i(e) {
    return 12 === e.length ? parseInt(e.substring(0, 2)) : 16 === e.length ? parseInt(e.substring(0, 3)) : 0;
}

function l(e) {
    if (12 === e.length) {
        var t = "20" + e.substring(2, 4) + "/" + e.substring(4, 6) + "/" + e.substring(6, 8) + " 00:00:00";
        console.log("体检日期", t);
        var r = new Date().getTime() - new Date(t).getTime();
        return Math.ceil(r / 864e5);
    }
    if (16 === e.length) {
        var n = "20" + e.substring(6, 8) + "/" + e.substring(8, 10) + "/" + e.substring(10, 12) + " 00:00:00";
        console.log("体检日期", n);
        var s = new Date().getTime() - new Date(n).getTime();
        return Math.ceil(s / 864e5);
    }
    return 0;
}